using JGSY.CMS.LowCode.Platform.Application.DTOs;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 文章应用服务接口
    /// 提供文章管理相关的业务逻辑操作
    /// </summary>
    public interface IArticleAppService
    {
        /// <summary>
        /// 获取所有文章
        /// </summary>
        /// <returns>文章列表</returns>
        Task<IEnumerable<ArticleDto>> GetAllAsync();

        /// <summary>
        /// 根据ID获取文章
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>文章信息</returns>
        Task<ArticleDto?> GetByIdAsync(long id);

        /// <summary>
        /// 根据别名获取文章
        /// </summary>
        /// <param name="slug">文章别名</param>
        /// <returns>文章信息</returns>
        Task<ArticleDto?> GetBySlugAsync(string slug);

        /// <summary>
        /// 根据分类获取文章列表
        /// </summary>
        /// <param name="categoryId">分类ID</param>
        /// <returns>文章列表</returns>
        Task<IEnumerable<ArticleDto>> GetByCategoryAsync(long categoryId);

        /// <summary>
        /// 获取置顶文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>置顶文章列表</returns>
        Task<IEnumerable<ArticleDto>> GetStickyArticlesAsync(int count = 10);

        /// <summary>
        /// 获取最新文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>最新文章列表</returns>
        Task<IEnumerable<ArticleDto>> GetLatestArticlesAsync(int count = 10);

        /// <summary>
        /// 获取热门文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>热门文章列表</returns>
        Task<IEnumerable<ArticleDto>> GetPopularArticlesAsync(int count = 10);

        /// <summary>
        /// 分页获取文章列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="categoryId">分类ID</param>
        /// <param name="status">状态过滤</param>
        /// <param name="isSticky">是否置顶</param>
        /// <returns>分页文章列表</returns>
        Task<(IEnumerable<ArticleDto> Items, int TotalCount)> GetPagedAsync(
            int pageIndex, 
            int pageSize, 
            string? keyword = null, 
            long? categoryId = null,
            byte? status = null,
            bool? isSticky = null);

        /// <summary>
        /// 创建文章
        /// </summary>
        /// <param name="articleDto">文章信息</param>
        /// <returns>创建的文章</returns>
        Task<ArticleDto> CreateAsync(ArticleDto articleDto);

        /// <summary>
        /// 更新文章
        /// </summary>
        /// <param name="articleDto">文章信息</param>
        /// <returns>更新的文章</returns>
        Task<ArticleDto> UpdateAsync(ArticleDto articleDto);

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteAsync(long id);

        /// <summary>
        /// 批量删除文章
        /// </summary>
        /// <param name="ids">文章ID列表</param>
        /// <returns>删除的数量</returns>
        Task<int> BatchDeleteAsync(IEnumerable<long> ids);

        /// <summary>
        /// 更新文章状态
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <param name="status">状态</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateStatusAsync(long id, byte status);

        /// <summary>
        /// 发布文章
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否发布成功</returns>
        Task<bool> PublishAsync(long id);

        /// <summary>
        /// 取消发布文章
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否取消成功</returns>
        Task<bool> UnpublishAsync(long id);

        /// <summary>
        /// 设置文章置顶
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <param name="isSticky">是否置顶</param>
        /// <returns>是否更新成功</returns>
        Task<bool> SetStickyAsync(long id, bool isSticky);

        /// <summary>
        /// 增加文章阅读量
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> IncrementViewCountAsync(long id);

        /// <summary>
        /// 增加文章点赞数
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> IncrementLikeCountAsync(long id);

        /// <summary>
        /// 检查文章别名是否存在
        /// </summary>
        /// <param name="slug">文章别名</param>
        /// <param name="excludeId">排除的文章ID</param>
        /// <returns>是否存在</returns>
        Task<bool> SlugExistsAsync(string slug, long? excludeId = null);

        /// <summary>
        /// 搜索文章
        /// </summary>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns>搜索结果</returns>
        Task<(IEnumerable<ArticleDto> Items, int TotalCount)> SearchAsync(
            string keyword, 
            int pageIndex = 1, 
            int pageSize = 20);
    }
}
